// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   majorSecondKind_register_ok.java

package hr.config.file;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class majorSecondKind_register_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public majorSecondKind_register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			java.io.PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String first_kind_ID = "";
				String first_kind_name = "";
				String first_kind = request.getParameter("first_kind");
				for (StringTokenizer tokenTO = new StringTokenizer(first_kind, "/"); tokenTO.hasMoreTokens();)
				{
					first_kind_ID = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
				}

				String second_kind_name = request.getParameter("second_kind_name");
				String sqll = (new StringBuilder("select * from hr_config_major_second_kind where first_kind_ID='")).append(first_kind_ID).append("' and first_kind_name='").append(first_kind_name).append("' and second_kind_name='").append(second_kind_name).append("'").toString();
				ResultSet rs = hr_db.executeQuery(sqll);
				if (rs.next())
				{
					response.sendRedirect("hr/config/file/majorSecondKind_register_ok_a.jsp");
				} else
				{
					String second_kind_ID = "";
					String sql2 = (new StringBuilder("select * from hr_config_major_second_kind where first_kind_ID='")).append(first_kind_ID).append("' and first_kind_name='").append(first_kind_name).append("' order by second_kind_ID desc").toString();
					ResultSet rs2 = hr_db.executeQuery(sql2);
					if (rs2.next())
					{
						String aaa = rs2.getString("second_kind_ID");
						if (aaa.equals(" "))
							aaa = rs2.getString("second_kind_ID");
						else
							aaa = rs2.getString("second_kind_ID");
						int code1 = Integer.parseInt(aaa);
						code1--;
						second_kind_ID = (new StringBuilder(String.valueOf(code1 + 100))).toString().substring(1);
						int code2 = code1 + 1;
						code1 += 2;
						String sql3 = (new StringBuilder("update hr_config_major_second_kind set second_kind_ID='")).append(code1).append("' where first_kind_ID='").append(first_kind_ID).append("' and first_kind_name='").append(first_kind_name).append("' and  second_kind_ID='").append(code2).append("'").toString();
						hr_db.executeUpdate(sql3);
					}
					String sql = (new StringBuilder("insert into hr_config_major_second_kind(first_kind_ID,first_kind_name,second_kind_ID,second_kind_name) values('")).append(first_kind_ID).append("','").append(first_kind_name).append("','").append(second_kind_ID).append("','").append(second_kind_name).append("')").toString();
					hr_db.executeUpdate(sql);
					response.sendRedirect("hr/config/file/majorSecondKind_register_ok_b.jsp");
				}
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
